Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

220
Visualizações
How to refer to nested objects with "-" in the name

I am having trouble referring to any variables with "-" in the variable name. I feel the answer is something very simple but I can't figure it out.

For Example

var headers = {
  "content-type": "application/json;charset=UTF-8",
  "content-length": "261",
  "connection": "close",
  "date": "Fri, 01 Apr 2022 09:12:56 GMT",
  "server": "nginx",
  "vary": "Accept-Encoding",
  "x-mbx-uuid": "88911a02-ff75-4cc0-b8ef-1ea4ab0edabd",
  "x-mbx-used-weight": "10",
  "x-mbx-used-weight-1m": "10"
}

to refer to an element, the following works

console.log(headers.server)

But the following doesnt work because javascript doesn't recognise - . How do I refer to x-mbx-used-weight-1m in this case?

console.log(headers.x-mbx-used-weight-1m)

You can see it is not recognised in JSFiddle

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to use square brackets and quote marks:

headers["x-mbx-used-weight-1m"]
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda